<?php

class Country_Model_DbTable_Fields extends Engine_Db_Table
{
  protected $_rowClass = 'Country_Model_Field';
  
  function getBasicField(){
    $select = $this->select()
         ->where('parent_id = ?',0);
    $result = $this->fetchAll($select);
    return $result;
         
  }
  
  public function getChildrenId($parent_id){
    $select = $this->select()
         ->where('parent_id = ?',$parent_id);
    $rows = $this->fetchAll($select);
    
    $result = array();
    $result[] = 0;
    foreach( $rows as $row){
        $result[] = $row->field_id;
    }
    return $result;
  }
  
  public function getInfoField(){
    $select = $this->select()
         ->where('parent_id != ?',0);
    $result = $this->fetchAll($select);
    return $result;
  }
  public function getAllField($params = array()){
    $select = $this->select();
    if (isset($params['order']) && !empty($params['order']) ) {
        $orderD = 'asc';
        if (isset($params['orderDirection']) && !empty($params['orderDirection'])) 
            $orderD = $params['orderDirection'];
            
        $select->order($params['order'].' '.$orderD);
    } else {
        $select->order('title asc');
    }
    
    $result = $this->fetchAll($select);
    return $result;
  }
  
  public function getParentFields(){
     $select = $this->select()
                    ->where('parent_id = ?',0);
     $rows = $this->fetchAll($select);
     return $rows;
  }
}
